public class Solution10 {
    //673. 最长递增子序列的个数
    public int findNumberOfLIS(int[] nums) {
        //dp[i]表示以i结尾的最长....个数
        int n = nums.length;
        int[] len = new int[n]; // 以i结尾的最长递增子序列的长度
        int[] count = new int[n]; //以i结尾的 最长递增子序列的个数
        for (int i = 0; i < n; i++) {
            len[i] = count[i] = 1;
        }
        int retLen = 1;
        int retCount = 1;
        for (int i = 1; i < n; i++) {
            for (int j = i-1; j >= 0; j--) {
                if (nums[i] > nums[j]) {
                    if (len[i] == len[j]+1) {
                        count[i] += count[j];
                    } else if (len[j]+1> len[i]) {
                        len[i] = len[j] + 1;
                        count[i] = count[j];
                    }
                }
            }
            if (retLen == len[i]) {
                retCount += count[i];
            } else if (retLen < len[i]) {
                retLen = len[i];
                retCount = count[i];
            }
        }
        return retCount;
    }
}
